<HTML>
<HEAD>
    <link href="prism.css" rel="stylesheet" />
<style>
body {
    margin-left: 120px;
}

P {
    width: 50em;
}

pre{
    width : 50em;
    background-color: #FFFFFF;
}
</style>
<script>
function fileClick(a) {

        var linkTag = a.href;
        var substring = "file:///";
        if (linkTag.includes(substring)) {
            var url = '/cnm/document/v/downloadLocalfile?path=' + encodeURIComponent(linkTag);
            fileOpen(url);
        }
        else {
            window.open(linkTag, '_blank');
        }
    }

    function fileOpen(url) {
        $.ajax({
            url: url,
            complete: function (jqxhr, txt_status) {
                console.log("Complete: [ " + txt_status + " ] " + jqxhr);
                if (txt_status == 'success') {
                    window.open(url, '_self');
                }
                else {
                    alert("File not found[404]!");
                }
                // }
            }
        });
    }
    </script>

<script>

var g_binary = [];
var g_tempbuff = [];
var g_width;
var g_height;
var g_Ticker;
var g_stopped = 0;


function flushBinary(ctx, binary, width, height)
{
   var x = 0;
   var y = 0;

   ctx.fillStyle="#000000";
   ctx.fillRect(0, 0, width *3, height *3);

   ctx.fillStyle="#FFFFFF";
   for(y=0;y<height;y++)
   {
      for(x=0;x<width;x++)
      {
         if(g_binary[y*width+x])
         {
            ctx.fillRect(x *3, y *3, 3, 3);
         }
      }
   }
}


var g_plane =
{
  width : 0,
  height : 0,
}

function plane_reset(width, height)
{
    var x;
    var y;
    
   g_plane.width = width;
   g_plane.height = height;
   
   for (y = 0; y < g_plane.height; y++)
    {
        for (x = 0; x < g_plane.width; x++)
        {
            g_binary[y*g_width+x] =  Math.random() < 0.3 ? 1 : 0;
        }
   }
}


    function Nneighbours(x, y)
    {
        var ix;
        var iy;
        var answer;
        
        answer = 0;
        
        for (iy = -1; iy < 2; iy++)
        {
            if (y + iy < 0 || y + iy >= g_plane.height)
                continue;
            for (ix = -1; ix < 2; ix++)
            {
                if (x + ix  < 0 || x + ix >= g_plane.width)
                   continue;
               if (ix == 0 && iy == 0)
                    continue;
                answer += g_binary[(y + iy) * g_plane.width + (x + ix)];
            }
        }
        
        return answer;
    }

function steplife()
{
  var dx;
  var dy;
  var d2;
  
  var x;
  var y;
  var nn;
  
  
  
  for (y = 0; y < g_plane.height; y++)
  {
      for (x = 0; x < g_plane.width; x++)
      {
          nn = Nneighbours(x, y);
        
          if (g_binary[y * g_plane.width + x] == 1)
          {
              if (nn > 3)
              {
                    g_tempbuff[y * g_plane.width + x] = 0;
              }
              else if (nn < 2)
              {
                    g_tempbuff[y * g_plane.width + x] = 0;
              }
              else
              {
                  g_tempbuff[y*g_plane.width + x] = 1
              }
          }
          else
          {
              if (nn == 3)
              {
                  g_tempbuff[y * g_plane.width + x] = 1;
              }
              else
              {
                  g_tempbuff[y * g_plane.width + x] = 0;
              }
          }
      }
      

  }
  for (y = 0; y < g_plane.height; y++)
  {
      for (x = 0; x < g_plane.width; x++)
      {
          g_binary[y * g_plane.width + x] = g_tempbuff[y * g_plane.width + x];
       }
  }
  return 0;
}


var temp = 0;

function step()
{
   var step;

   temp++;
   
  steplife();

   step = document.getElementById("step");
   step.innerHTML = temp.toString();
   
}

function tickettyTick()
{
   var can;
   var ctx;
   
   step();
   
   can = document.getElementById("life");
   ctx = can.getContext("2d");
   flushBinary(ctx, g_binary, g_width, g_height);
   ctx.fillStyle = "#FF0000"

}

function setUp()
{
  var can;
  var i;
  
  can = document.getElementById("life");

  g_width = Math.floor(can.width/3);
  g_height = Math.floor(can.height/3);
  for(i=0;i<g_width*g_height;i++)
  {
     g_binary.push(0);
     g_tempbuff.push(0);
  }

  plane_reset(g_width, g_height);
  
}

function clickstopstart()
{
   var but;
 
   but = document.getElementById("stopstart_but");
   if(g_stopped)
   {
      g_Ticker = setInterval(tickettyTick, 100);
      but.innerHTML = "Stop";
      g_stopped = 0;
   }
   else
   {
      clearInterval(g_Ticker);
      but.innerHTML = "Start";
      g_stopped = 1;
   }
}
 
 

function myFunction()
{
   setUp();
   g_Ticker = setInterval(tickettyTick, 100);
}

</script>

</HEAD>
<BODY bgcolor="#c0c0ff" onload="myFunction()">
    <script src="prism.js"></script>
    <A href ="https://github.com/MalcolmMcLean"> <IMG src = "Cartoon_Owl_clip_art.svg" width = "64" height = "62" alt="Malcolm's github site"> </IMG> </A>
    <A href ="index.html"> <IMG src = "babyxrc_logo.svg" alt="Baby X Resource Compiler" width = "64" height = "62"> </IMG> </A>
    &nbsp;&nbsp;
    <IMG src = "babyxrc-banner.svg" width = "256" height = "62" alt = "Baby X RC banner"></IMG>
<H1>Hello Baby X</H1>

<div style="width:50em">
<IMG src="BabyXLogos/baby-x-rc-logo.svg" alt="Baby X logo" width="120" style="float:right">
    &nbsp;&nbsp;&nbsp;&nbsp;
</div>

<P>
<A href="https://malcolmmclean.github.io/babyx">Baby X</A> is a project designed to allow user to write small or "baby" programs. At its heart is the <A href="https://github.com/MalcolmMcLean/babyx">Baby X library</A>, a library of C functions designed to prove a simple but adequate windowing system which works on both Linux and Windows. The other main component is the resource compiler <A href ="index.html">BabyXRC</A>, which is designed to package up fonts, images, strings, and so on for use with <A href=" https://malcolmmclean.github.io/babyx/BabyXHelloWorld.html">Baby X programs</A>. And the other component is the filing system <A href="BabyXFS.html">BabyXFS</A>, which provides a virtual filing system for computers with the <A href="FileSystemXML.html">FilesSystem XML</A> files. All three components are independent of the other. You can use the Baby X resource compiler to compile resources for non Baby X programs, and you can use BabyXFS to add virtual filing to non-Baby X programs.
</P>
<P>
Baby X is designed mainly for hobby programmers, but is competely free to anyone for any use, with the exception of components not authored by me, where you must respect the attached licence terms.
</P>
<P>
There are two projects hosted on github, <A href="https://github.com/MalcolmMcLean/babyx">Baby X</A> itself, and the <A href="https://github.com/MalcolmMclean/babyxrc">Baby X resource compiler</A>. You need to get both projects to use the whole of Baby X. BabyXFS is held within the Baby X resource compiler git repository. You then get your resources - pngs, jpegs, audio and so on, and then use the compiler to convert them to C source files. You the add the C source to a a program which incorporates the Baby X source files, and you get a GUI program which will compile and run for either Linux or Windows.
</P>
<P>
However if you want to add an entire directory as a resource, the resource compiler can't add that, because there is no way of doing that portably, and so you need BabyXFS, the Baby X FileSystem component. You convert the folder you wish to add to to FileSystem XML file, and then add that to the program as a string using the resorce compiler. You then add the file bbx_filesystem.c and its dependencies to your Baby X program, and you can access the FileSystem XML file you hold internally. And if you need to edit the FileSystem XML file, you can do that with an editor, or with the programs in the BabyXFS subsystem.
</P>
<P>
<H4> Baby X is pro-life</H4>
<div>
<canvas id="life" width="300" height="300"></canvas>
</div>
<div>
    <button id = "stopstart_but" onclick="clickstopstart()">Stop</button>
    &nbsp;&nbsp;
    Steps: <span id = "step" style = "background-color:white"> step </span>
    
</div>
<P>
And Baby X loves stories. Read his favourite book, <A href="StToms/index.html">Adam and Abagail go to St Tom's</A>
</P>
<BR>
And that is the world of Baby X. Have fun programming.
</P>
<P>
Malcolm
</P>

</BODY> </HTML>

